package com.zjj.lbw.designpattern.factorymethod;

/**
 * @author zhanglei.zjj
 * @description 简单工厂模式，它不属于23种设计模式，只能算是一种编程技巧
 * @date 2023/7/12 15:50
 */
public class SimpleFactoryTest {
    public static void main(String[] args) {
        Product product = SimpleFactory.createProduct("B");
        product.method1();
    }
}

interface Product {
    void method1();
}

class ProductA implements Product {

    @Override
    public void method1() {
        System.out.println("ProductA.method1 executed.");
    }
}

class ProductB implements Product {

    @Override
    public void method1() {
        System.out.println("ProductB.method1 executed.");
    }
}


// 简单工厂
class SimpleFactory {
    public static Product createProduct(String type) {
        if ("A".equals(type)) {
            return new ProductA();
        } else if ("B".equals(type)) {
            return new ProductB();
        }

        return null;
    }
}
